//package com.xiaocikuai.smallchunks.controller.Transaction;
//
//
//import com.xiaocikuai.smallchunks.entity.Transaction.Promotional;
//import com.xiaocikuai.smallchunks.entity.User.Duser;
//import com.xiaocikuai.smallchunks.service.Transaction.impl.PromotionalServiceImpl;
//import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//
///**
// * <p>
// *  前端控制器
// * </p>
// *
// * @author author1
// * @since 2024-07-13
// */
//@RestController
//@RequestMapping("/promotional")
//public class PromotionalController {
//
//    @Resource
//    PromotionalServiceImpl promotionalService;
//
//
//
//
//    @PostMapping("/insert")
//    public Resultd addPromotional(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
//        if (promotionalService.save(promotional)) {
//            return Resultd.ok().data("info", "注册成功");
//        } else {
//            return Resultd.error().data("info", "注册失败");
//        }
//    }
//
//    @PostMapping("/delete")
//    public Resultd deletePromotional(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
//        if (promotionalService.removeById(promotional.getPromotionalId())) {
//            return Resultd.ok().data("info", "删除成功");
//        } else {
//            return Resultd.error().data("info", "删除失败");
//        }
//    }
//
//    @PostMapping("/update")
//    public Resultd updatePromotional(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
//        if (promotionalService.updateById(promotional)) {
//            return Resultd.ok().data("info", "更新成功");
//        } else {
//            return Resultd.error().data("info", "更新失败");
//        }
//    }
//
//    @PostMapping("/selectById")
//    public Resultd selectById(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
//        Promotional promotional1 = promotionalService.getById(promotional.getPromotionalId());
//
//        if (promotional1!= null) {
//            return Resultd.ok().data("info",promotional1);
//        } else {
//            return Resultd.error().data("info", "未找到对应记录");
//        }
//    }
//
//    //领取优惠券
//    @PostMapping("/getpromotionl")
//    public Resultd getpromotionl(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
//        if (promotionalService.updateById(promotional)) {
//
//            return Resultd.ok().data("info", "更新成功");
//        } else {
//            return Resultd.error().data("info", "更新失败");
//        }
//    }
//
//
//
//
//}
package com.xiaocikuai.smallchunks.controller.Transaction;

import com.xiaocikuai.smallchunks.entity.Transaction.Promotional;
import com.xiaocikuai.smallchunks.entity.User.Duser;
import com.xiaocikuai.smallchunks.service.Transaction.impl.PromotionalServiceImpl;
import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author1
 * @since 2024-07-13
 */
@Api(tags = "促销控制器")
@RestController
@RequestMapping("/api/promotional")
public class PromotionalController {

    @Resource
    PromotionalServiceImpl promotionalService;

    @ApiOperation(value = "添加促销信息")
    @PostMapping("/insert")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "promotional", value = "促销信息", required = true, dataType = "Promotional", paramType = "body")
    })
    public Resultd addPromotional(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
        if (promotionalService.save(promotional)) {
            return Resultd.ok().data("info", "注册成功");
        } else {
            return Resultd.error().data("info", "注册失败");
        }
    }

    @ApiOperation(value = "删除促销信息")
    @PostMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "promotional", value = "促销信息", required = true, dataType = "Promotional", paramType = "body")
    })
    public Resultd deletePromotional(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
        if (promotionalService.removeById(promotional.getPromotionalId())) {
            return Resultd.ok().data("info", "删除成功");
        } else {
            return Resultd.error().data("info", "删除失败");
        }
    }

    @ApiOperation(value = "更新促销信息")
    @PostMapping("/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "promotional", value = "促销信息", required = true, dataType = "Promotional", paramType = "body")
    })
    public Resultd updatePromotional(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
        if (promotionalService.updateById(promotional)) {
            return Resultd.ok().data("info", "更新成功");
        } else {
            return Resultd.error().data("info", "更新失败");
        }
    }

    @ApiOperation(value = "根据 ID 查询促销信息")
    @PostMapping("/selectById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "promotional", value = "促销信息（包含 ID）", required = true, dataType = "Promotional", paramType = "body")
    })
    public Resultd selectById(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
        Promotional promotional1 = promotionalService.getById(promotional.getPromotionalId());

        if (promotional1!= null) {
            return Resultd.ok().data("info",promotional1);
        } else {
            return Resultd.error().data("info", "未找到对应记录");
        }
    }

    @ApiOperation(value = "领取优惠券")
    @PostMapping("/getpromotionl")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "promotional", value = "促销信息", required = true, dataType = "Promotional", paramType = "body")
    })
    public Resultd getpromotionl(@RequestHeader("Authorization") String token, @RequestBody Promotional promotional) {
        if (promotionalService.updateById(promotional)) {

            return Resultd.ok().data("info", "更新成功");
        } else {
            return Resultd.error().data("info", "更新失败");
        }
    }
}
